package blog.ideablog.controller;

import blog.ideablog.model.vo.QiniuUploadInfoVO;
import blog.ideablog.model.vo.Results;
import blog.ideablog.provider.QiniuFileProvider;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("与文件操作相关的api接口")
@RestController
public class FileController {

    @Autowired
    private QiniuFileProvider qiniuFileProvider;
    @Value("${qiniu.server}")
    private String uploadUrl;
    @Value("${qiniu.url}")
    private String imageUrl;

    @ApiOperation("获取七牛云上传凭证")
    @GetMapping("/file/qiniu/token")
    public Results<QiniuUploadInfoVO> getToken() {
        String token = qiniuFileProvider.getUploadToken();
        QiniuUploadInfoVO info = QiniuUploadInfoVO.builder()
                .token(token)
                .uploadUrl(uploadUrl)
                .imageUrl(imageUrl)
                .build();
        return Results.ok("token获取成功", info);
    }

}
